package com.zhongshengnetwork.rightbe.common.customview;

import android.app.Dialog;
import android.content.Context;
import android.graphics.Color;
import android.view.Display;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TextView;

import com.zhongshengnetwork.rightbe.R;
import com.zhongshengnetwork.rightbe.common.AppThemeUtils;
import com.zhongshengnetwork.rightbe.common.ScreenUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by luojingxing on 2018/11/29.
 */

public class ShareDialog {
    private Context context;
    public Dialog dialog;
    private TextView txt_cancel;
    public LinearLayout friend_share;
    public LinearLayout wx_share;
    public LinearLayout wb_share;
    public LinearLayout qq_share;
    public LinearLayout zone_share;
    private Display display;

    public ShareDialog(Context context) {
        this.context = context;
        WindowManager windowManager = (WindowManager) context
                .getSystemService(Context.WINDOW_SERVICE);
        display = windowManager.getDefaultDisplay();
    }

    public ShareDialog builder() {
        // ��ȡDialog����
        View view = LayoutInflater.from(context).inflate(
                R.layout.share_dialog_layout, null);

        LinearLayout xdialog = (LinearLayout) view.findViewById(R.id.xdialog);
        xdialog.setBackgroundColor(AppThemeUtils.getInstance().getMainColor());
        LinearLayout share_dialog = (LinearLayout) view.findViewById(R.id.share_dialog);
        share_dialog.setBackgroundResource(AppThemeUtils.getInstance().getShareBg());
        TextView share_frend = (TextView) view.findViewById(R.id.share_frend);
        share_frend.setTextColor(AppThemeUtils.getInstance().getTextColorOfWeiJu());
        TextView share_wx = (TextView) view.findViewById(R.id.share_wx);
        share_wx.setTextColor(AppThemeUtils.getInstance().getTextColorOfWeiJu());
        TextView share_wb = (TextView) view.findViewById(R.id.share_wb);
        share_wb.setTextColor(AppThemeUtils.getInstance().getTextColorOfWeiJu());
        TextView share_qq = (TextView) view.findViewById(R.id.share_qq);
        share_qq.setTextColor(AppThemeUtils.getInstance().getTextColorOfWeiJu());
        TextView share_zone = (TextView) view.findViewById(R.id.share_zone);
        share_zone.setTextColor(AppThemeUtils.getInstance().getTextColorOfWeiJu());

        // ����Dialog��С���Ϊ��Ļ���
        view.setMinimumWidth(display.getWidth());

        // ��ȡ�Զ���Dialog�����еĿؼ�
        txt_cancel = (TextView) view.findViewById(R.id.txt_cancel);
        txt_cancel.setBackgroundResource(AppThemeUtils.getInstance().getShareBg());
        txt_cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
            }
        });

        //菜单
        friend_share = (LinearLayout) view.findViewById(R.id.friend_share);
        wx_share = (LinearLayout) view.findViewById(R.id.wx_share);
        wb_share = (LinearLayout) view.findViewById(R.id.wb_share);
        qq_share = (LinearLayout) view.findViewById(R.id.qq_share);
        zone_share = (LinearLayout) view.findViewById(R.id.zone_share);

        // ����Dialog���ֺͲ���
        dialog = new Dialog(context, R.style.ActionSheetDialogStyle);
        dialog.setContentView(view);
        Window dialogWindow = dialog.getWindow();
        dialogWindow.setGravity(Gravity.LEFT | Gravity.BOTTOM);
        WindowManager.LayoutParams lp = dialogWindow.getAttributes();
        lp.x = 0;
        lp.y = 0;
        dialogWindow.setAttributes(lp);

        return this;
    }


    public ShareDialog setCancelable(boolean cancel) {
        dialog.setCancelable(cancel);
        return this;
    }

    public ShareDialog setCanceledOnTouchOutside(boolean cancel) {
        dialog.setCanceledOnTouchOutside(cancel);
        return this;
    }


    public void show() {
        dialog.show();
    }
}
